<?php
include 'util.php';

// 洗牌
function shuffleCard(){
	$myFile = file_get_contents('src\json\poker.json');
	$myDataArr = json_decode(prepareJSON($myFile), true); 
	$cards = $myDataArr['standard'];
	shuffle($cards);
	shuffle($cards);
	shuffle($cards);
	
	$newCards = array();
	for($i=0;$i<count($cards);$i++){
		$newCards[$i]=$cards[$i]['id'];
	}
	file_put_contents('src\temp\new_poker.json',json_encode($newCards));
}

// 发牌，每人4张
function dealCard(){
	$pokerFile = file_get_contents('src\temp\new_poker.json');
	$cards = json_decode(prepareJSON($pokerFile), true); 
	$newCards = array();
	for($i=0;$i<6;$i++){
		$newCards[$i]=array($cards[$i*4],$cards[$i*4+1],$cards[$i*4+2],$cards[$i*4+3]);
	}
	
	$statusFile = file_get_contents('src\json\gameStatus.json');
	$myDataArr = json_decode(prepareJSON($statusFile), true);
	$myDataArr['cardIndex']='24';
	$myDataArr['gamePhase']='2';
	for($i=0;$i<6;$i++){
		$myDataArr['playerInfo'][$i]['cards']=$newCards[$i];
	}
	var_dump($myDataArr['playerInfo'][0]['cards']);
	file_put_contents('src\json\gameStatus.json',json_encode($myDataArr));
}

shuffleCard();
dealCard();
?>